﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BAL.Controller;
using EntityObjects;
using System.IO;

namespace PresentationLayer.View
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        Email em;
        public ViewCatalogueForClerkContol control;
        public List<Category> catList;
        static public string fstIndex = "0";
        protected void Page_Load(object sender, EventArgs e)
        {
            control = new ViewCatalogueForClerkContol();
            if (!IsPostBack)
            {                
                ddCategory.DataSource = control.getCategory();
                ddCategory.DataValueField = "CategoryId";
                ddCategory.DataTextField = "CategoryName";
                ddCategory.DataBind();
                List<String> str = control.getBin();
                foreach (string st in str)
                {
                    ddCategory0.Items.Add(st);
                }
                ddCategory0.DataBind();
                ViewState[fstIndex] = control.getCatalogue();
                Bind();
            }
        }

        private void Bind()
        {
            if (ViewState[fstIndex] != null)
            {
                Label1.Visible = false;
                foo.DataSource = ViewState[fstIndex];             
            }
            else {
                foo.DataSource = ViewState[fstIndex];
                Label1.Visible = true;
            }
            foo.DataBind();
        }

         protected void btnSearch_Click(object sender, EventArgs e)
        {
            int id = Convert.ToInt16(ddCategory.SelectedValue);
            String bin = ddCategory0.SelectedItem.ToString();
            String desc = TextBox1.Text.ToString();
            if (bin == "All")
            {
                ViewState["0"] = control.searchWithoutBin(id, desc);              
            }
            else if (bin != "All")
            {
                ViewState["0"]=control.searchWithBin(id, desc, bin);               
            }
            Bind();
        }

         protected void foo_PageIndexChanging(object sender, GridViewPageEventArgs e)
         {
             foo.PageIndex = e.NewPageIndex;
             Bind();
         }

         protected void ddCategory_SelectedIndexChanged(object sender, EventArgs e)
         {

         }

        
        
    
    }
}